//
//  JXBarButtonItem.swift
//  sinaWeibo
//
//  Created by jixiao on 15/12/27.
//  Copyright © 2015年 heimacast. All rights reserved.
//

import UIKit

//添加分类
extension UIBarButtonItem {
    
    //添加便利构造函数
    
    convenience init(imageName:String?=nil,title:String?=nil,target: AnyObject?, action: Selector) {
        //调用自己的其他初始化方法
        
        self.init()
        
        let button=UIButton()
        
        //这个方法会不会崩溃?
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if imageName != nil {
            
            //设置image的图片
            button.setImage(UIImage(named: imageName!), forState: .Normal)
            
            button.setImage(UIImage(named: "\(imageName!)_highlighted"), forState: .Highlighted)
//            print("\(button.imageView?.image)")
            
            
        }
        
        if title != nil {
            
            button.setTitle(title, forState: .Normal)
            
            //设置字体大小
            
            button.titleLabel?.font=UIFont.systemFontOfSize(15)
            
            
            button.setTitleColor(UIColor(white: 80/255, alpha: 1), forState: .Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            
        }
        
        button.sizeToFit()
        
        //这里直接可以设置不用强转啊??
        customView=button
        
    }
    
    
    
    
}
